package com.yidu.ladder.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.ladder.base.dao.StaffDao;
import com.yidu.ladder.base.domain.Staff;
import com.yidu.ladder.base.domain.StaffVo;
import com.yidu.ladder.base.domain.Standard;
import com.yidu.ladder.base.domain.Time;
import com.yidu.ladder.base.service.StaffService;


@Service
public class StaffServiceImpl implements StaffService {
	@Autowired
	private StaffDao staffDao;

	public StaffDao getStaffDao() {
		return staffDao;
	}

	public void setStaffDao(StaffDao staffDao) {
		this.staffDao = staffDao;
	}

	public StaffServiceImpl() {
		super();
	}


	public StaffServiceImpl(StaffDao staffDao) {
		super();
		this.staffDao = staffDao;
	}

	@Override
	public List<Staff> selectAll() {
		return staffDao.selctAll();
	}

	@Override
	public Map<String, Object> pageQueryStaff(StaffVo staffVo) {
		//设置页面
		int page = (staffVo.getPage()-1)*staffVo.getLimit();
		staffVo.setPage(page);
		//调用Dao层方法分页查询
		List<Staff> qu = staffDao.pageQueryStaff(staffVo);
		//每次查询得到相应的记录数
		int count = staffDao.countUserByCriteria(staffVo);
		//创建一个Map接收数据返回给前端
		Map<String, Object> map = new HashMap<String, Object>();
		//map存放code
		map.put("code", 0);
		//map存放count
		map.put("count", count);
		//map存放数据data
		map.put("data", qu);
		//返回一个map
		return map;
	}

	@Override
	public int addstaff(Staff staff) {
		return staffDao.addstaff(staff);
	}

	@Override
	public int updatepicture(Staff staff) {
		return staffDao.update(staff);
	}

	@Override
	public Boolean updatefreeze(String staffIdstr, String flag) {
		//创建传参的Map集合
		Map<String, Object> paraMap = new HashMap<String, Object>();
		//判断进行冻结还是还原
        String useable =flag;
		//根据逗号分割IDsplit
        String[] staffIds = staffIdstr.split(",");
        //定义执行结果返回的总数 因为成功返回1，所以把所有执行结果加起来正好就等于ID的总数
		int total = 0;
		//遍历archivesIds数组
		for (int i = 0; i < staffIds.length; i++) {
			// 添加IDstaffId
			paraMap.put("staffId", staffIds[i]);
			//添加要修改的状态useable
			paraMap.put("useable", useable);
			//执行
			int result = staffDao.updatefreeze(paraMap);
			//计数
			total += result;
		}
		//返回计数true false
		return total == staffIds.length ? true : false;
	}

	@Override
	public List<Standard> selectAllSdsdd() {
		return staffDao.selctAllSdsdd();
	}

	@Override
	public List<Time> selectAllTestte() {
		return staffDao.selectAllTes();
	}

}